{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "!cp /home/husein/ssd3/llm/__label__standard-malay.jsonl combine.jsonl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('combine.jsonl', 'a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "files = [\n",
    "    '/home/husein/ssd3/llm/fb-dedup.jsonl',\n",
    "    '/home/husein/ssd3/llm/carigold.jsonl',\n",
    "    '/home/husein/ssd3/llm/c-cari-com-my.jsonl',\n",
    "    '/home/husein/ssd3/llm/hardwarezone-sg.jsonl',\n",
    "    '/home/husein/ssd3/llm/SeriousKopitiam.json',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/husein/ssd3/llm/fb-dedup.jsonl\n",
      "/home/husein/ssd3/llm/carigold.jsonl\n",
      "/home/husein/ssd3/llm/c-cari-com-my.jsonl\n",
      "/home/husein/ssd3/llm/hardwarezone-sg.jsonl\n",
      "/home/husein/ssd3/llm/SeriousKopitiam.json\n"
     ]
    }
   ],
   "source": [
    "for file in files:\n",
    "    print(file)\n",
    "    with open(file) as fopen:\n",
    "        if file.endswith('.jsonl'):\n",
    "            count = 0\n",
    "            for l in fopen:\n",
    "                data = json.loads(l)\n",
    "                if isinstance(data, dict):\n",
    "                    if 'original' in data:\n",
    "                        t = data['original']\n",
    "                    elif 'text' in data:\n",
    "                        if data['text'] == ' __NOEDITSECTION__':\n",
    "                            continue\n",
    "                        t = data['text']\n",
    "                else:\n",
    "                    t = data\n",
    "                f.write(f'{json.dumps(t)}\\n')\n",
    "                count += 1\n",
    "                if count > 5e6:\n",
    "                    break\n",
    "        else:\n",
    "            data = json.load(fopen)\n",
    "            for t in data:\n",
    "                f.write(f'{json.dumps(t)}\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from glob import glob\n",
    "\n",
    "jawi = glob('/home/husein/ssd3/jawi/wiki-rumi-jawi-*.jsonl')\n",
    "len(jawi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "for file in jawi:\n",
    "    with open(file) as fopen:\n",
    "        for l in fopen:\n",
    "            t = json.loads(l)['jawi']\n",
    "            f.write(f'{json.dumps(t)}\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "f.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
